<?php
    include ('init.php');
    function rewardClass() {
        return array("三等奖", "谢谢参与", "二等奖", "谢谢参与","一等奖", "三等奖", "再接再厉 ", "谢谢参与", "再接再厉", "谢谢参与");
    }
    function makeRand($max) {
        $retry = false;
        do {
            $random = rand(0, $max - 1);
            if ($random == 4) {
                if (rewardDate()) {
                    if (file_exists('yidengjiang.txt')) {
                        $retry = true;
                    } else {
                        $retry = false;
                        file_put_contents('yidengjiang.txt', 'aa');
                    }
                } else {
                    $retry = true;
                }
            }
            if ($random == 2) {
                $shopFile = "erdengjiang_".$_GET['shopId'].'.txt';
                if (rewardDate()) {
                    if (file_exists($shopFile)) {
                        $retry = true;
                    } else {
                        $retry = false;
                        file_put_contents($shopFile, 'aa');
                    }
                } else {
                    $retry = true;
                }
            }
        } while ($retry);
        return $random;
    }
    function rewardDate() {
        $day = date("j");
        return ($day == 20 || $day == 21);
    }
    $id = $_POST["id"];
    $arr = rewardClass();
    $res = makeRand(count($arr))+1;
    $sql = "UPDATE zhuanpanyonghu SET reward_info= '".$arr[$res-1]."' WHERE did = ".$_GET['lastId'];
    $dbh->exec($sql);
    //saveResult($res);'
    echo ($id == 1)?$res:json_encode($arr);
 ?>